home *** CD-ROM | disk | FTP | other *** search
/ Disc to the Future 2 / Disc to the Future Part II Programmer's Reference (Wayzata Technology)(6013)(1992).bin / MAC / THINKC / 4_0 / NOFLICKE / MBARMAIN.C1 < prev    next >
Text File  |  1990-12-27  |  4KB  |  187 lines

  1. #include <OSUtil.h>
  2. #include <WindowMgr.h>
  3. #include <MenuMgr.h>
  4. #include <EventMgr.h>
  5. #include <ToolBoxUtil.h>
  6.  
  7. #ifndef NULL
  8. #define NULL    0
  9. #endif
  10.  
  11. SysEnvRec SysEnv;                /* Machine environment record */
  12. Boolean    WNEIsImplemented;
  13. Boolean Suspended = false;
  14.  
  15. #define UnImplTrap        0xa89f
  16. #define _WaitNextEvent    0xab60
  17.  
  18. void Init (void);
  19. Boolean TrapAvailable (short, short);
  20. void PositionRect (Rect *, Point *);
  21. void PositionWindow (WindowPtr, Point *);
  22.  
  23. Boolean notDone = true;
  24. MenuHandle AppleMenu, FileMenu, EditMenu, FlickerMenu, Flicker1Menu, Flicker2Menu;
  25. WindowPtr AboutWPtr;
  26. PicHandle AboutPic;
  27. Boolean flickerEnabled = true;
  28. Boolean flic1Enabled = true;
  29. Boolean flic2Enabled = true;
  30. Boolean editEnabled = true;
  31.  
  32. main ()
  33. {
  34.     Init ();
  35.     
  36.     while (notDone) {
  37.         EventLoop ();
  38.     }
  39.     
  40.     RemoveMBarPatch ();
  41. }
  42.  
  43. void Init ()
  44. {
  45.     short menuID;
  46.     
  47.     MaxApplZone ();
  48.     FlushEvents (everyEvent - diskMask, 0 );
  49.     InitGraf (&thePort);
  50.     InitFonts ();
  51.     InitWindows ();
  52.     InitMenus ();
  53.     TEInit ();
  54.     InitDialogs (NULL);                /* install restart proc */
  55.     InitCursor ();
  56.     InitMBarPatch ();
  57.  
  58.     /* Find out if WaitNextEvent is implemented. First get version 2 of the
  59.         environment record.    */
  60.     SysEnvirons (2, &SysEnv);
  61.     WNEIsImplemented = (SysEnv.machineType < 0 ? false :
  62.                 TrapAvailable (_WaitNextEvent, ToolTrap));
  63.                 
  64.     /* install our menus    */
  65.     menuID = 128;
  66.     if (!(AppleMenu = GetMenu (menuID++)))
  67.         ExitToShell ();
  68.         
  69.     if (!(FileMenu = GetMenu (menuID++)))
  70.         ExitToShell ();
  71.  
  72.     if (!(EditMenu = GetMenu (menuID++)))
  73.         ExitToShell ();
  74.  
  75.     if (!(FlickerMenu = GetMenu (menuID++)))
  76.         ExitToShell ();
  77.  
  78.     if (!(Flicker1Menu = GetMenu (menuID++)))
  79.         ExitToShell ();
  80.  
  81.     if (!(Flicker2Menu = GetMenu (menuID++)))
  82.         ExitToShell ();
  83.  
  84.     AddResMenu (AppleMenu, 'DRVR');        /* add desk accessories */
  85.     
  86.     InsertMenu (AppleMenu, 0);
  87.     InsertMenu (FileMenu, 0);
  88.     InsertMenu (EditMenu, 0);
  89.     InsertMenu (FlickerMenu, 0);
  90.     InsertMenu (Flicker1Menu, 0);
  91.     InsertMenu (Flicker2Menu, 0);
  92.     DrawMenuBar ();
  93.     
  94.     /* get our window, and the about picture    */
  95.     if (!(AboutWPtr = GetNewWindow (128, NULL, -1L)))
  96.         ExitToShell ();
  97.         
  98.     if (!(AboutPic = GetPicture (128)))
  99.         ExitToShell ();
  100.         
  101.     HNoPurge (AboutPic);
  102.     SizeWindow (AboutWPtr,
  103.                 (*AboutPic)->picFrame.right - (*AboutPic)->picFrame.left,
  104.                 (*AboutPic)->picFrame.bottom - (*AboutPic)->picFrame.top,
  105.                 false);
  106.     PositionWindow (AboutWPtr, NULL);
  107.     SetPort (AboutWPtr);
  108.     ClipRect (&AboutWPtr->portRect);
  109. }
  110.  
  111. Boolean TrapAvailable (tNumber, tType)
  112.     short tNumber;
  113.     short tType;
  114. {
  115.     /* Check and see if a trap exists */
  116.     return (NGetTrapAddress (tNumber, tType) != NGetTrapAddress (UnImplTrap, ToolTrap));
  117. }
  118.  
  119.  
  120. void ShowHideAbout ()
  121. {
  122.     if (((WindowPeek) AboutWPtr)->visible)
  123.         HideWindow (AboutWPtr);
  124.     
  125.     else
  126.         ShowWindow (AboutWPtr);
  127. }
  128.  
  129. void ShowAbout ()
  130. {
  131.     ShowWindow (AboutWPtr);
  132. }
  133.  
  134. void PositionRect (r, pt)
  135.     Rect *r;
  136.     Point *pt;
  137. {
  138.     Rect screen;
  139.     short scrW, scrH;
  140.     short rW, rH;
  141.     short dH, dV;
  142.     Point tl;
  143.  
  144.     screen = screenBits.bounds;
  145.     
  146.     rW = r->right - r->left;
  147.     rH = r->bottom - r->top;
  148.     
  149.     scrW = screen.right - screen.left;
  150.     scrH = screen.bottom - screen.top;
  151.     
  152.     dH = -r->left + (scrW - rW)/2;
  153.     dV = -r->top + (scrH - MBarHeight - rH)/3 + MBarHeight;
  154.     
  155.     OffsetRect (r, dH, dV);
  156.     
  157.     tl.h = r->left;
  158.     tl.v = r->top;
  159.     
  160.     *pt = tl;
  161. }
  162.  
  163. void PositionWindow (wPtr, pt)
  164.     WindowPtr wPtr;
  165.     Point *pt;
  166. {
  167.     Rect portRect;
  168.     Point tl;
  169.  
  170.     if (!wPtr) {
  171.         if (pt) {
  172.             pt->h = -1;
  173.             pt->v = -1;
  174.         }
  175.     
  176.         return;
  177.     }
  178.     
  179.     portRect = wPtr->portRect;
  180.     
  181.     PositionRect (&portRect, &tl);
  182.     MoveWindow (wPtr, portRect.left, portRect.top, false);
  183.     
  184.     if (pt)
  185.         *pt = tl;
  186. }
  187.